package com.quick.threadtest;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadExecutorTest {
    public static void main(String[] args) {
        ExecutorService executor = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 10; i++) {
            MyTask1 myTask1 = new MyTask1();
            executor.execute(myTask1);
        }
        executor.shutdown();
        System.out.println("------------------");
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        for (int i = 0; i < 10; i++) {
            MyTask1 myTask1 = new MyTask1();
            executorService.execute(myTask1);
        }
        executorService.shutdown();
        System.out.println("------------------");

        ExecutorService executorService1 = Executors.newCachedThreadPool();
        for (int i = 0; i < 10; i++) {
            MyTask1 myTask1 = new MyTask1();
            executorService1.execute(myTask1);
        }
        executorService1.shutdown();
    }

}
class MyTask1 implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName());
    }
}